home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / kriegspi / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-30  |  800 b   |  57 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: list.c,v 1.3 87/02/12 11:02:40 schoch Exp $";
  3. #endif
  4.  
  5. /* list.c */
  6. #include "constants.h"
  7.  
  8. #ifndef FALSE
  9. #define FALSE    0
  10. #define TRUE    1
  11. #endif
  12.  
  13. struct IN
  14. {
  15.     int i;
  16.     struct IN *n;
  17. };
  18. typedef struct IN *LIST;
  19.  
  20. LIST
  21. linsert (list, number)
  22.     LIST list;
  23.     int number;
  24. {
  25.     LIST cell;
  26.  
  27.     char *malloc ();
  28.     cell = (LIST) malloc (sizeof (struct IN));
  29.     cell->i = number;
  30.     cell->n = list;
  31.     return cell;
  32. }
  33.  
  34. LIST
  35. lmember (number, list)
  36.     int number;
  37.     LIST list;
  38. {
  39.     while (list != NIL) {
  40.         if (list->i == number)
  41.             return list;
  42.         list = list->n;
  43.     }
  44.     return FALSE;
  45. }
  46.  
  47. lfront (sublist, list)
  48.     LIST sublist, list; /* both must be non-NIL */
  49.     /* Allows easy deletion, when combined with lmember.  Violent. */
  50. {
  51.     int n;
  52.  
  53.     n = list->i;
  54.     list->i  = sublist->i;
  55.     sublist->i = n;
  56. }
  57.